package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.Psychological;
import com.hs.service.PsychologicalService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PsychologicalController
 * @Description TODO
 * @Author wangzhihao
 * @Date 2025年08月08日 21:16
 * @Version 1.0
 */
@RestController
@RequestMapping("psychological")
public class PsychologicalController {
    @Autowired
    PsychologicalService psychologicalService;
    @PostMapping
    public R insert(@RequestBody Psychological psychological) {
        int insert = psychologicalService.insert(psychological);
        if (insert > 0) {
            return R.ok();
        }
        return R.fail();
    }
    @PutMapping
    public R update(@RequestBody Psychological psychological) {
        int update = psychologicalService.update(psychological);
        if (update > 0) {
            return R.ok();
        }
        return R.fail();
    }
    @DeleteMapping("{id}")
    public R delete(@PathVariable("id") int id) {
        int delete = psychologicalService.delete(id);
        if (delete > 0) {
            return R.ok();
        }
        return R.fail();
    }
    @GetMapping("{id}")
    public R select(@PathVariable("id") int id) {
        Psychological psychological = psychologicalService.select(id);
        if (psychological != null) {
            return R.ok(psychological);
        }
        return R.fail();
    }
    @GetMapping("all")
    public R selectAll(@RequestParam(required = false,defaultValue = "1")int pageNum,
                       @RequestParam(required = false,defaultValue = "10")int pageSize) {
        PageInfo<Psychological> psychologicalPageInfo = psychologicalService.selectByExample(pageNum,pageSize);
        return R.ok(psychologicalPageInfo);
    }
}
